#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include<thread>
#include<mutex>
#include<condition_variable>
#include<future>
#include<vector>
#include<memory>
using namespace std;
class threadpool
{
public:
	using ptr = shared_ptr<threadpool>;
	using Functor = function<void(void)>;
	threadpool(int htr_count=1):_stop(false)
	{
		for (int i = 0; i < htr_count; i++)
		{
			_threads.emplace_back(&threadpool::entry,this );
		}
	}
	void stop()
	{
		if (_stop)
			return;
		_stop = true;
		_cv.notify_all();
		for (auto& thread:_threads)
		{
			thread.join();
		}
	}

	/*template<typename F,typename ...Args>
	auto push(F&& func, Args&& ...args) ->std::future<decltype(func(args...))>
	{
		using return_type = decltype(func(args...));
		auto temp_func = std::bind(std::forward<F>(func), std::forward<Args>(args)...);
		auto task = make_shared<packaged_task<return_type()>>(temp_func);
		std::future<return_type> fu = task->get_future();
		{
			unique_lock<mutex> lock(_mutex);
			_taskpool.push_back([task]() {
				(*task)(); });
			_cv.notify_one();
		}
		return fu;
	}*/

	template<typename F,typename ...Args>
	auto push(F &&func,Args&& ...args) ->std::future<decltype(func(args...))>
	{
		using return_type = decltype(func(args...));
		auto temp_func = std::bind(forward<F>(func), forward<Args>(args)...);
		auto task = make_shared<packaged_task<return_type()>>(temp_func);
		future<return_type> fu = task->get_future();
		{
			unique_lock<mutex> lock(_mutex);
			_taskpool.push_back([task]() { (*task)(); });
			_cv.notify_one();
		}
		return fu;

	}

	void entry()
	{
		while (!_stop)
		{
			std::vector<Functor> temp_taskpool;
			{
				unique_lock<mutex> lock(_mutex);
				_cv.wait(lock, [this]() { return _stop || !_taskpool.empty(); });
				temp_taskpool.swap(_taskpool);
			}
			for (auto& task : temp_taskpool)
			{
				task();
			}
		}
	}



private:
	atomic<bool> _stop;
	mutex _mutex;
	condition_variable _cv;
	vector<Functor> _taskpool;
	vector<thread> _threads;
};


int Add(int i, int j)
{
	return  i + j;
}

//int main()
//{
//	threadpool pool(2);
//	vector<std::future<int>> v1;
//	for (int i = 0; i < 10; i++)
//	{
//		std::future<int> fu = pool.push(Add, 11, i);
//		std::cout << fu.get() << endl;
//	}
//	pool.push([]() {
//		cout << "sssssssssssssss\n"; });
//	pool.stop();
//
//	return 0;
//}

int main()
{
	vector<int> nums = { 1,2,3,4,5,6,7 };
	int n = nums.size();
	int k = 3;
	k % n;
	reverse(nums.begin(), nums.end());
	reverse(nums.begin(), nums.begin() + k-1);
	reverse(nums.begin() + k, nums.end());
	cout << *--nums.end() << endl;
	return 0;
}